package model.initializeEntity;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import model.entity.Company;
import BaseClass.BaseInitialize;
import BaseClass.HibernateUtil;

public class IntCompany extends BaseInitialize<Company> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -1507892996024525351L;


	public void initialize() throws IOException, ClassNotFoundException,
			SQLException {
		Logger log = LoggerFactory.getLogger(this.getClass());
		try {
			session = HibernateUtil.getSessionFactory().openSession();
			Transaction tx = session.beginTransaction();

			inFile = new InputStreamReader(new FileInputStream(ObjectPath),
					"MS950");
			brFile = new BufferedReader(inFile);

			while ((Line = brFile.readLine()) != null) {
				Company comp = new Company();
				comp.setComPanyName(Line);
				comp.setCreatdate(new Timestamp(new Date().getDay()));
				comp.setUpdatedate(new Timestamp(0));
				session.save(comp);
			}
			tx.commit();

		} catch (HibernateException e) {
			e.printStackTrace();
		} finally {
			session.disconnect();
		}
	}
}
